package main

/**
io/ioUtil中的readFile可以读取整个文件  文件不能太大
io.Copy()拷贝文件
*/
import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type charCount struct {
	chCount    int
	numCount   int
	spaceCount int
}

func main() {
	file, err1 := os.Open("C:/test.log")
	if err1 != nil {
		fmt.Println("读取失败", err1)
		return
	}
	//reader := bufio.NewReader(os.Stdin)
	reader := bufio.NewReader(file)
	defer file.Close()
	/*	line,boo, err := reader.ReadLine()
		if err != nil {
			fmt.Print("read fill", err)
			return
		}
		fmt.Println(boo)
		fmt.Print(string(line))*/
	var count charCount
	for {
		str, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		if err != nil && err != io.EOF {
			fmt.Printf("read fill err: %v", err)
			return
		}

		strArray := []rune(str)
		for _, val := range strArray {
			//switch 后面写了值就对应执行 ，没写值就判断case后面的条件是否成立
			switch {
			case val > 'a' && val < 'z':
				fallthrough
			case val > 'A' && val < 'Z':
				count.chCount++
			case val == ' ' || val == '\t':
				count.spaceCount++
			default:
				count.numCount++
			}
		}
	}

}
